﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Microsoft.Practices.Unity;

namespace Enter.Mvc.Base.Infrastructure
{
	public class MyChyControllerFactory : DefaultControllerFactory
	{
		private readonly IUnityContainer container;

		public MyChyControllerFactory(IUnityContainer container)
		{
			this.container = container;
		}

		protected override IController GetControllerInstance(System.Web.Routing.RequestContext requestContext, Type controllerType)
		{
			if (controllerType != null)
			{
				IController icontroller = container.Resolve(controllerType) as IController;
				if (typeof(Controller).IsAssignableFrom(controllerType))
				{
					Controller controller = icontroller as Controller;

					if (controller != null)
						controller.ActionInvoker = container.Resolve<IActionInvoker>();

					return icontroller;
				}
				return icontroller;
			}
			return null;


		}
	}
   
}
